//
//  MessageItem.m
//  QBIM
//
//  Created by liu nian on 14-3-19.
//  Copyright (c) 2014年 liunian. All rights reserved.
//

#import "MessageItem.h"
#import "MessageCenter.h"
#import "PayloadBase.h"
#import "PacketUtility.h"

@implementation MessageItem
- (id)initWithMessageContent:(MessageContent *)content{
    if (self == [super init]) {

        self.U = content.U;
        self.S = content.S;
        self.R = content.R;
        self.T = content.T;
        self.MT = content.MT;
        self.PT = content.PT;
        self.P = content.P;
        self.CT = content.CT;

    }
    return self;
}
//- (void)setDate:(NSDate *)date{
//    if (date != _date) {
//        _date = date;
//    }
//}

- (NSDate*)date{
    if (self.CT) {
        return [PacketUtility dateFromString:self.CT];
    }
    return [NSDate date];
}

- (JSBubbleMediaType)bubbleMediaType{
    if (self.MT == PacketContentTypeText) {
        return JSBubbleMediaTypeText;
    }else if (self.MT == PacketContentTypeImage) {
        return JSBubbleMediaTypeImage;
    }
    return JSBubbleMediaTypeText;
}

- (JSBubbleMessageType)bubbleMessageType{
    if (self.S == [[[MessageCenter shared] currentAuthPayload] ID]) {
        return JSBubbleMessageTypeOutgoing;
    }
    return JSBubbleMessageTypeIncoming;
}

@end
